/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SolicitacaoReserva.java
 *
 * Created on 04/07/2011, 22:30:40
 */
package Formularios;

import DAO.SalaDAO;
import Logica.Sala;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import java.util.logging.Logger;

/**
 *
 * @author Vinicius
 */
public class SolicitacaoReserva extends javax.swing.JFrame {
    
    private static final Logger log = Logger.getLogger(SolicitacaoReserva.class.getName());
    
    String idioma;

    /** Creates new form SolicitacaoReserva */
    public SolicitacaoReserva(String idioma) {
        
        log.info("Formulário solicitação de reserva iniciado");
        
          initComponents();
          
          this.idioma = idioma;
    }
    private int id;

    SolicitacaoReserva(int id) {
        this.id = id;
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jBSolicitar = new javax.swing.JButton();
        jBDesmarcar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTDay = new javax.swing.JTextField();
        jCalendar1 = new com.toedter.calendar.JCalendar();
        jSpinHoraInicio = new com.toedter.components.JSpinField();
        jSpinField2 = new com.toedter.components.JSpinField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 102, 153));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Solicitação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Horário Início:");

        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Horário Fim:");

        jBSolicitar.setText("Solicitar");
        jBSolicitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSolicitarActionPerformed(evt);
            }
        });

        jBDesmarcar.setText("Desmarcar");
        jBDesmarcar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBDesmarcarActionPerformed(evt);
            }
        });

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Dia:");

        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Dia do calendário:");

        jTDay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTDayActionPerformed(evt);
            }
        });

        jCalendar1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {//GERA A AÇÃO PRA TROCA DE PROPRIEDADE  
            public void propertyChange(java.beans.PropertyChangeEvent evt) { //GERA EVENTO  
                jCalendar1PropertyChange(evt); //CHAMA O MÉTODO CONTENDO A ROTINA  
            }  
        });  

        jSpinHoraInicio.setMaximum(20);
        jSpinHoraInicio.setMinimum(8);
        jSpinHoraInicio.setValue(8);

        jSpinField2.setMaximum(21);
        jSpinField2.setMinimum(9);
        jSpinField2.setValue(9);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSpinHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jCalendar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTDay, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(22, 22, 22)
                        .addComponent(jSpinField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(109, 109, 109)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jBDesmarcar)
                                .addContainerGap())
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jBSolicitar, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                .addGap(40, 40, 40))))))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBDesmarcar, jBSolicitar});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jSpinField2, jSpinHoraInicio});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jBSolicitar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addComponent(jSpinHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jSpinField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBDesmarcar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCalendar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"8-9", null, null, null, null, null, null},
                {"9-10", null, null, null, null, null, null},
                {"10-12", null, null, null, null, null, null},
                {"12-13", null, null, null, null, null, null},
                {"13-14", null, null, null, null, null, null},
                {"14-15", null, null, null, null, null, null},
                {"15-16", null, null, null, null, null, null},
                {"16-17", null, null, null, null, null, null},
                {"17-18", null, null, null, null, null, null},
                {"18-19", null, null, null, null, null, null},
                {"19-20", null, null, null, null, null, null},
                {"20-21", null, null, null, null, null, null}
            },
            new String [] {
                "", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBSolicitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSolicitarActionPerformed
        log.info("Solicitando reserva");
        
        try {
            Sala sala = new Sala();
            sala.setId(this.id);
            SalaDAO daoSala = new SalaDAO();
            if (sala.getSituacao() == "solicitado") {
                JOptionPane.showMessageDialog(null, "Sala solicitada");
            } else {
                sala.setSituacao("solicitado");
                daoSala.altera(sala);
            }
        } catch (SQLException ex) {
            System.out.println("erro ao alterar sala");
        }

    }//GEN-LAST:event_jBSolicitarActionPerformed

    private void jBDesmarcarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDesmarcarActionPerformed
        dispose();
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jBDesmarcarActionPerformed

    private void jTDayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTDayActionPerformed
    }//GEN-LAST:event_jTDayActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowActivated

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        internacionaliza(idioma);
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowOpened

    private void jCalendar1PropertyChange(java.beans.PropertyChangeEvent evt) {

        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); //DEFINE FORMATO DE DATA
        String data = formato.format(jCalendar1.getDate()); //CONVERTE PRA STRING
        jTDay.setText(data);
    }

    /**
     * @param args the command line arguments
     */
    
    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SolicitacaoReserva().setVisible(true);
            }
        });
    }
     * 
     */
    
     public void internacionaliza(String locale) {
    ResourceBundle palavras = ResourceBundle.getBundle("Idiomas.lingua_"+locale);
    
    this.setTitle(palavras.getString("SR.Titulo"));
    jLabel1.setText(palavras.getString("SR.D"));
    jLabel2.setText(palavras.getString("SR.HI"));
    jLabel3.setText(palavras.getString("SR.HF"));
    jBSolicitar.setText(palavras.getString("SR.Sol"));
    jLabel4.setText(palavras.getString("SR.DC"));
    jBDesmarcar.setText(palavras.getString("SR.Des"));
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, (palavras.getString("SR.Solicitação")), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255)));
    
    
     }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBDesmarcar;
    private javax.swing.JButton jBSolicitar;
    private com.toedter.calendar.JCalendar jCalendar1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private com.toedter.components.JSpinField jSpinField2;
    private com.toedter.components.JSpinField jSpinHoraInicio;
    private javax.swing.JTextField jTDay;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
